<?php
namespace app\index\controller;

use app\index\model\Users;
use think\Controller;


class Login extends Controller
{
    public function _initialize()
    {
        parent::_initialize();
        header('Access-Control-Allow-Origin: *');
    }
    public function index()
    {
        $data = input('param.');
        $msg = '账号不存在或密码错误';
        if(!isset($data['username']) || !isset($data['password']) || !isset($data['remember']))
            return ajax_return(302);
        else{
            $pwd = encryption($data['password']);
            $model = new Users();
            $model->fields = 'ID,user_pass,user_nickname as name,user_phone as phone,status';
            $model->map['user_phone'] = $data['username'];
            $res = $model->get_one();
            if(!$res)
            {
                return ajax_return(404,$msg);
            }
            else
            {
                $res = data_trans($res);
                if($pwd === $res['user_pass'])
                {
                    unset($res['user_pass']);
                    return ajax_return(200,'successful',$res);
                }
                else
                {
                    return ajax_return(404,$msg);
                }
            }
        }
    }
}
